<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教师后台-不学也通-系部列表</title>
    <link rel="shortcut icon" href="../康笑长结业课.jpg" type="image/x-icon">
    <style>
        .container {
            min-height: 100vh;
        }

        .container .nav {
            height: 100%;
            background-color: #fff;
        }

        .link-secondary{
            text-decoration: none;
        }
        .link-secondary:hover{
            color: #0d6efd !important;
            
        }
        
        td img{
            max-width: 120px;
        }
    </style>
</head>

<body>
    <!-- container是bootstrap的居中窄的显示方案 -->
    <div class="container bg-body">
        <div class="row">
            <div class="col-md-2 leftmenu" id="leftmenu">
                
            </div>
            <div class="col-md-9 col-xs-12 kc ms-3">
                <div class="row mt-3 pd-3 border-bottom border-secondary">
                    <div class="col-md-2">系部列表</div>
                    <div class="col-md-2 offset-md-8">
                        <a class="nav-link link-success" href="./create_depart.html">
                            <i class="bi bi-people-fill"></i>
                            添加系部
                        </a>
                    </div>
            </div>
            <div class="row mt-3">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>序号</th>
                            <th>系部名称</th>
                            <th>系部编码号</th>
                            <th>学校编码号</th>
                            <th>创建时间</th>
                            <th>更新时间</th>
                            <th class="text-center">功能</th>
                        </tr>
                    </thead>
                    <tbody id="tbody"></tbody>
                </table>
           </div>
       </div>
   </div>
</div> 
    <script type="module" src="../js/main.js"></script>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/common.js"></script>
    <script>
        $(document).ready(function(){
           $.get("http://unicloud.codecore.cn/ms/departs",{},function(params){
            if(params.errCode == 0){
                let data = params.data;
                for (let i = 0; i < data.length; i++){  
                    let elem = data[i]
                    $("#tbody").append($(`<tr>
                            <td>${i+1}</td>
                            <td>${elem.department_name}</td>
                            <td>${elem.department_code}</td>
                            <td>${elem.school_code}</td>
                            <td>${elem.create_time}</td>
                            <td>${elem.update_time}</td>
                            <td class="text-center">
                               <button class="btn btn-success btn-sm" data-id="${elem._id}">编辑</button>
                               <button class="btn btn-danger btn-sm" data-id="${elem._id}">删除</button>
                             </td>
                     </tr>`));
                }
            }
           })
           // 编辑
           $("#tbody").delegate("button.btn-success", "click",function(){
                let data = $(this).data();
                location.href = `./edit_depart.html?id=${data.id}`
            });
            // 删除
            $("#tbody").delegate("button.btn-danger","click",function(){
                let data= $(this).data();
                $.post("http://unicloud.codecore.cn/ms/departRemove",{id:data.id},function(params){
                    if(params.errCode == 0){
                        location.reload()
                    }else{
                        alert("删除异常")
                    }
                
                })
            });
    })
    </script>
</body>

</html>
</body>
</html>